﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for CustomerBus
/// </summary>
public class CustomerBus
{
    CustomerDAL cusDAL;
	public CustomerBus()
	{
        cusDAL = new CustomerDAL();
    }
    public bool InsertUpdateCustomer(Customer cus)
    {
        bool check = false;
        if (cusDAL.InsertUpdateCustomer(cus) != 0) 
        {
            check = true;
        }
        return check;
    }
    public bool Delete_Customer(int customer_id)
    {
        bool check = false;
        if (cusDAL.Delete_customer(customer_id) != 0)
        {
            check = true;
        }
        return check;
    }
    public DataTable getAllCustomer()
    {
        return cusDAL.getAllCustomer();
    }
    public Customer getCustomerById(int customer_id)
    {
        DataTable dt = new DataTable();
        dt = cusDAL.getCustomerByID(customer_id);
        Customer cus = new Customer();
        cus.Customer_id = Convert.ToInt32(dt.Rows[0][0].ToString());
        cus.First_name = dt.Rows[0][1].ToString();
        cus.Last_name = dt.Rows[0][2].ToString();
        cus.Email = dt.Rows[0][3].ToString();
        cus.Password = dt.Rows[0][4].ToString();
        cus.Address = dt.Rows[0][5].ToString();
        cus.City = dt.Rows[0][6].ToString();
        cus.Phone = dt.Rows[0][7].ToString();
        cus.Customer_group_id = Convert.ToInt32(dt.Rows[0][8].ToString());
        cus.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        return cus;
    }
    public Customer getCustomerByFirstName(string Fname)
    {
        DataTable dt = new DataTable();
        dt = cusDAL.getCustomerByFirstName(Fname);
        Customer cus = new Customer();
        cus.Customer_id = Convert.ToInt32(dt.Rows[0][0].ToString());
        cus.First_name = dt.Rows[0][1].ToString();
        cus.Last_name = dt.Rows[0][2].ToString();
        cus.Email = dt.Rows[0][3].ToString();
        cus.Password = dt.Rows[0][4].ToString();
        cus.Address = dt.Rows[0][5].ToString();
        cus.City = dt.Rows[0][6].ToString();
        cus.Phone = dt.Rows[0][7].ToString();
        cus.Customer_group_id = Convert.ToInt32(dt.Rows[0][8].ToString());
        cus.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        return cus;
    }
    public Customer getCustomerByLastName(string LName)
    {
        DataTable dt = new DataTable();
        dt = cusDAL.getCustomerByLastName(LName);
        Customer cus = new Customer();
        cus.Customer_id = Convert.ToInt32(dt.Rows[0][0].ToString());
        cus.First_name = dt.Rows[0][1].ToString();
        cus.Last_name = dt.Rows[0][2].ToString();
        cus.Email = dt.Rows[0][3].ToString();
        cus.Password = dt.Rows[0][4].ToString();
        cus.Address = dt.Rows[0][5].ToString();
        cus.City = dt.Rows[0][6].ToString();
        cus.Phone = dt.Rows[0][7].ToString();
        cus.Customer_group_id = Convert.ToInt32(dt.Rows[0][8].ToString());
        cus.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        return cus;
    }
    public Customer getCustomerByEmail(string email)
    {
        DataTable dt = new DataTable();
        dt = cusDAL.getCustomerByEmail(email);
        Customer cus = new Customer();
        if (dt.Rows.Count != 0) 
        {
            cus.Customer_id = Convert.ToInt32(dt.Rows[0][0].ToString());
            cus.First_name = dt.Rows[0][1].ToString();
            cus.Last_name = dt.Rows[0][2].ToString();
            cus.Email = dt.Rows[0][3].ToString();
            cus.Password = dt.Rows[0][4].ToString();
            cus.Address = dt.Rows[0][5].ToString();
            cus.City = dt.Rows[0][6].ToString();
            cus.Phone = dt.Rows[0][7].ToString();
            cus.Customer_group_id = Convert.ToInt32(dt.Rows[0][8].ToString());
            cus.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        }

        return cus;
    }
    public Customer getCustomerByCGID(int id)
    {
        DataTable dt = new DataTable();
        dt = cusDAL.getCustomerByCGID(id);
        Customer cus = new Customer();
        if (dt.Rows.Count != 0)
        {
            cus.Customer_id = Convert.ToInt32(dt.Rows[0][0].ToString());
            cus.First_name = dt.Rows[0][1].ToString();
            cus.Last_name = dt.Rows[0][2].ToString();
            cus.Email = dt.Rows[0][3].ToString();
            cus.Password = dt.Rows[0][4].ToString();
            cus.Address = dt.Rows[0][5].ToString();
            cus.City = dt.Rows[0][6].ToString();
            cus.Phone = dt.Rows[0][7].ToString();
            cus.Customer_group_id = Convert.ToInt32(dt.Rows[0][8].ToString());
            cus.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        }
        return cus;
    }
    public bool CheckLogin(string email, string pass) 
    {
        DataTable dt = new DataTable();
        dt = cusDAL.Login(email, pass);
        if (dt.Rows.Count > 0) 
        {
            return true;
        }
        return false;

    }
    public bool ChangePass(string email, string passold, string passnew)
    {
        bool check = false;
        if (cusDAL.ChangePassword(email, passold, passnew) != 0) 
        {
            check = true;
        }
        return check;
    }
    public DataTable getCustomerByID(int customer_id)
    {
        DataTable dt = new DataTable();
        dt = cusDAL.getCustomerByID(customer_id);
        return dt;
    }
    
}